﻿@model IEnumerable<WebUI.Models.RecuperAttachInfo>
@{
    List<string> prefixs = new List<string>();         
}
<div class="attach-fieldset">    
    @foreach (var attach in Model)
    {
        string prefix = attach.DepartProfilesID;
        prefixs.Add(prefix);
        int maxLength = 0;
        int.TryParse(attach.DepartmentProfile.SettingValueC, out maxLength);
        <div class="attach-field">
            @Html.Hidden(prefix + "_ID", attach.ID)
            @Html.Hidden(prefix + "_DepartProfilesID", attach.DepartProfilesID)
            @Html.Hidden(prefix + "_RecuperID", attach.RecuperID)
            <div class="editor-label">
                <label for="@(prefix + "_AttachValue")">@attach.AttachTitle</label>
                @Html.Hidden(prefix + "_AttachTitle", attach.AttachTitle)
            </div>
            <div class="editor-field">
                @if (attach.DepartmentProfile.SettingValueB == "System.Int32")
                {
                    Dictionary<string, object> htmlAttr = new Dictionary<string, object>();
                    htmlAttr["id"] = prefix + "_AttachValue";
                    htmlAttr["onkeyup"] = @"this.value=this.value.replace(/\D/g,'')";
                    htmlAttr["onafterpaste"] = @"this.value=this.value.replace(/\D/g,'')";
                    if (maxLength > 0)
                    {
                        htmlAttr["maxlength"] = maxLength;
                    }
                    <span class="small-input">
                    @Html.TextBox(prefix + "_AttachValue", attach.AttachValue, htmlAttr)
                    </span>
                }
                else if (attach.DepartmentProfile.SettingValueB == "System.Double")
                {
                    Dictionary<string, object> htmlAttr = new Dictionary<string, object>();
                    htmlAttr["id"] = prefix + "_AttachValue";
                    htmlAttr["onkeyup"] = @"this.value = this.value.replace(/[^\d.]/g,'');this.value = this.value.replace(/^\./g,'');this.value = this.value.replace(/\.{2,}/g,'.');this.value = this.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');";
                    htmlAttr["onafterpaste"] = @"this.value = this.value.replace(/[^\d.]/g,'');this.value = this.value.replace(/^\./g,'');this.value = this.value.replace(/\.{2,}/g,'.');this.value = this.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');";
                    if (maxLength > 0)
                    {
                        htmlAttr["maxlength"] = maxLength;
                    }
                    <span class="small-input">
                    @Html.TextBox(prefix + "_AttachValue", attach.AttachValue, htmlAttr)
                    </span>
                }
                else if (attach.DepartmentProfile.SettingValueB == "System.DateTime")
                {
                    string g = prefix + "_AttachValue";
                    <span class="small-input">
                        @Html.TextBox(prefix + "_AttachValue", attach.AttachValue, new { id = g })
                    </span>
                    <script type="text/javascript">
                        $(function () { $('#@(g)').datepicker(); });
                    </script>
                }
                else if (attach.DepartmentProfile.SettingValueB == "System.Boolean")
                {
                    @Html.DropDownList(prefix + "_AttachValue", new SelectList(new List<SelectListItem>()
                            {
                                new SelectListItem(){ Text="是", Value="True"},
                                new SelectListItem(){ Text="否", Value="False"}
                            }, "Value", "Text", attach.AttachValue),
                            new
                            {
                                id = prefix + "_AttachValue"
                            });
                }
                else
                {
                    Dictionary<string, object> htmlAttr = new Dictionary<string,object>();
                    htmlAttr["id"] = prefix + "_AttachValue";
                    if (maxLength > 0)
                    {
                        htmlAttr["maxlength"] = maxLength;
                    }
                    if (maxLength <= 20)
                    {
                        @Html.TextBox(prefix + "_AttachValue", attach.AttachValue, htmlAttr)
                    }
                    else
                    {
                        @Html.TextArea(prefix + "_AttachValue", attach.AttachValue, htmlAttr)
                    }                    
                }
            </div>
        </div>
    }
    @Html.Hidden("RecuperAttachPrefixs", String.Join(",", prefixs))
    <div class="clear"></div>
</div>
